home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / '92_HACK / IR_MAN_ / KILLAPP.C < prev    next >
C/C++ Source or Header  |  1992-06-07  |  1KB  |  47 lines

  1. #include "KillApp.h"
  2.  
  3. /**********************************
  4.  
  5.     QuitApps
  6.     DTS Code Snippet to quit all running applications (except yourself)
  7.     
  8.     note: to work properly, the calling application must have a standard
  9.     event loop with menus (to support puppet string quits for apps that
  10.     don't support core appleevents.
  11.     
  12.     note#2: remember to set the applevent aware flag in your app if you use
  13.     this code
  14.     
  15.     written by Steven Falkenburg 9/4/91
  16.  
  17. **********************************/
  18.  
  19. /* quits an app of the given process id */
  20.  
  21. OSErr QuitAnApp(ProcessSerialNumber *proc)
  22. {
  23.     OSErr err;
  24.     AEAddressDesc target;
  25.     AppleEvent theAE,aeReply;
  26.     
  27.     theAE.dataHandle = aeReply.dataHandle = target.dataHandle = nil;
  28.     
  29.     err = AECreateDesc(typeProcessSerialNumber,(Ptr)proc,sizeof(ProcessSerialNumber),&target);
  30.     if (err!=noErr)
  31.         return err;
  32.  
  33.     err = AECreateAppleEvent(kCoreEventClass,kAEQuitApplication,&target,
  34.                     kAutoGenerateReturnID,kAnyTransactionID,&theAE);
  35.     if (err!=noErr) {
  36.         AEDisposeDesc(&target);
  37.         return err;
  38.     }
  39.      
  40.     err = AESend(&theAE,&aeReply,kAENoReply,kAENormalPriority,kNoTimeOut,nil,nil);
  41.         
  42.     AEDisposeDesc(&target);
  43.     AEDisposeDesc(&theAE);
  44.     
  45.     return err;
  46. }
  47.